package com.enjoyor.soa.traffic.restt.tpcms.dubbo.impl;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.tpcms.PassApplyDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboPassApplyService;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.IPassApplyConsumeService;
import com.enjoyor.soa.traffic.util.enums.EnumApplyStatus;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

/**
 * 申请单信息
 * 
 * @author fzj 2018年5月4日
 */
@Component
public class PassApplyConsumeService implements IPassApplyConsumeService {

    @Reference(version = "1.0.0", timeout = 10000)
    private IDubboPassApplyService dubboPassApplyService;

    /**
     * 新增申请信息
     */
    @Override
    public ResultPojo insertPassApply(PassApplyDto passApplyDto, String userName) {
        return dubboPassApplyService.insertPassApply(passApplyDto, userName);
    }

    /**
     * 新增并提交申请信息
     */
    @Override
    public ResultPojo insertSubmitPassApply(PassApplyDto passApplyDto, String userName) {
        String passApplyId = (String) dubboPassApplyService.insertPassApply(passApplyDto, userName).getResultList();
        String applyStatusId = EnumApplyStatus.WAITCHECK.getKey();
        return dubboPassApplyService.editPassApplyStatus(passApplyId, applyStatusId, userName);
    }

    /**
     * 删除申请信息
     */
    @Override
    public ResultPojo deletePassApply(String passApplyId, String userName) {
        return dubboPassApplyService.deletePassApply(passApplyId, userName);
    }

    /**
     * 修改申请信息
     */
    @Override
    public ResultPojo editPassApply(PassApplyDto passApplyDto, String userName) {
        return dubboPassApplyService.editPassApply(passApplyDto, userName);
    }

    /**
     * 修改并提交申请单
     */
    public ResultPojo editSubmitPassApply(PassApplyDto passApplyDto, String userName) {
        dubboPassApplyService.editPassApply(passApplyDto, userName);
        String passApplyId = passApplyDto.getPassApplyId();
        String applyStatusId = EnumApplyStatus.WAITCHECK.getKey();
        return dubboPassApplyService.editPassApplyStatus(passApplyId, applyStatusId, userName);
    }

    /**
     * 申请单提交审核
     */
    public ResultPojo submitPassApply(String passApplyId, String userName) {
        String applyStatusId = EnumApplyStatus.WAITCHECK.getKey();
        return dubboPassApplyService.editPassApplyStatus(passApplyId, applyStatusId, userName);
    }

    /**
     * 查询申请信息列表
     */
    @Override
    public ResultPojo getPassApplyList(String passApplyId, String applyPeople, String applyDept, String applyTypeId,
            String applyStartTime, String applyEndTime, String applyStatusId) {
        return dubboPassApplyService.getPassApplyList(passApplyId, applyPeople, applyDept, applyTypeId, applyStartTime,
                applyEndTime, applyStatusId);
    }

    /**
     * 查询申请信息分页
     */
    @SuppressWarnings("rawtypes")
    @Override
    public ResultPojo getPassApplyPage(Page page) {
        return dubboPassApplyService.getPassApplyPage(page);
    }

}
